<template>
  <view class="invite">
    <Navbar :title="t('invite.title')"> </Navbar>
    <view class="top">
      <view>{{ t('invite.code') }}</view>
      <text>{{ inviteCode }}</text>
    </view>
    <view class="bottom">
      <view class="b1">
        <view class="t1">{{ t('invite.link') }}</view>
        <view class="t2"
          >{{ inviteList.invite_link }}
          <image
            class="img"
            src="/static/invite/Frame.png"
            mode="scaleToFill"
            @click="copy"
        /></view>
      </view>
      <image class="img-a" :src="inviteList.invite_pic" mode="scaleToFill" />
      <view class="t3">{{ t('invite.long') }}</view>
    </view>
  </view>
</template>

<script setup>
import Navbar from '../../components/Navbar.vue';
import { ref, computed } from 'vue';
import api from '../../networks/apis';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();

//邀请好友图片
const inviteList = ref({});
const getInviteList = async () => {
  const res = await api.getInviteImgAPI();
  console.log('----->res', res.data);
  inviteList.value = res.data;
};
getInviteList();
const inviteCode = computed(() => {
  if (inviteList.value && inviteList.value.invite_link) {
    const regex = /inviteCode=(\d+)/; // 正则提取邀请码
    const match = inviteList.value.invite_link.match(regex);
    return match ? match[1] : '';
  }
  return '';
});
// console.log(inviteCode.value);
const copy = () => {
  uni.setClipboardData({
    data: inviteList.value.invite_link,
    success: function () {
      uni.showToast({
        title: 'Successful replication',
        icon: 'success',
        duration: 2000,
      });
    },
    fail: function () {
      console.log('复制失败');
      // 错误处理
    },
  });
};
</script>

<style lang="scss" scoped>
.invite {
  width: 750rpx;
  height: 1624rpx;
  background: linear-gradient(180deg, #040a40 0%, #042e40 0%, #0d1324 100%);
  .top {
    width: 688rpx;
    height: 254rpx;
    background-image: url('/static/invite/Rectangle 47.png');
    background-size: cover;
    background-repeat: no-repeat;
    margin: 18rpx auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    padding-top: 20rpx;
    view {
      height: 32rpx;
      font-size: 28rpx;
      font-family: Arial, Arial;
      font-weight: normal;
      color: rgba(255, 255, 255, 0.5);
      line-height: 33rpx;
    }
    text {
      height: 68rpx;
      font-size: 48rpx;
      font-family: Arial, Arial;
      font-weight: 900;
      color: #ffffff;
      line-height: 56rpx;
      letter-spacing: 2px;
    }
  }
  .bottom {
    width: 690rpx;
    height: 484rpx;
    background-image: url('/static/invite/Rectangle 33.png');
    background-size: cover;
    background-repeat: no-repeat;
    margin: 26rpx auto;
    padding-top: 10rpx;
    .b1 {
      display: flex;
      /* justify-content: center; */
      width: 652rpx;
      height: 102rpx;
      background-image: url('/static/invite/Rectangle 48.png');
      background-size: cover;
      background-repeat: no-repeat;
      margin: 18rpx auto;
      align-items: center;
      justify-content: space-between;
      padding: 0 20rpx;
      .t1 {
        height: 28rpx;
        font-size: 24rpx;
        font-family: Arial, Arial;
        font-weight: normal;
        color: rgba(255, 255, 255, 0.5);
        line-height: 28rpx;
        margin-right: 15rpx;
      }
      .t2 {
        /* height: 32rpx; */
        font-size: 28rpx;
        font-family: Arial, Arial;
        font-weight: bold;
        color: #ffffff;
        line-height: 33rpx;
      }
      .img {
        width: 30rpx;
        height: 30rpx;
      }
    }
    .img-a {
      display: block;
      width: 246rpx;
      height: 246rpx;
      border-radius: 16rpx 16rpx 16rpx 16rpx;
      opacity: 1;
      margin: 44rpx auto 0;
    }
    .t3 {
      height: 28rpx;
      font-size: 24rpx;
      font-family: Arial, Arial;
      font-weight: normal;
      color: rgba(255, 255, 255, 0.5);
      line-height: 28rpx;
      margin: 20rpx auto 0;
      text-align: center;
    }
  }
}
</style>
